package com.yanftch.json2ets

import com.intellij.openapi.actionSystem.AnAction
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.ui.DialogBuilder
import com.intellij.openapi.ui.DialogWrapper
import com.yanftch.json2ets.json2ets.generator.GeneratorDelegateJava
import com.yanftch.json2ets.json2ets.generator.MessageDelegate
import com.yanftch.json2ets.json2ets.parser.typescript.ParseType
import com.yanftch.json2ets.json2ets.views.Json2TsDialog

class Json2etsFileAction : AnAction() {
    private val generatorDelegate = GeneratorDelegateJava(MessageDelegate())

    override fun actionPerformed(event: AnActionEvent) {
        val dialog = Json2TsDialog(dialogTitle = "Create A ets File From Json")
        dialog.setOnGenerateListener(object : Json2TsDialog.OnGenerateClicked {
            override fun onClicked(rootName: String, json: String, parseType: ParseType) {
                dialog.close(DialogWrapper.OK_EXIT_CODE)
                generatorDelegate.runGenerationToFile(event, json, rootName, parseType)
            }
        })
        dialog.show()
    }

    override fun update(e: AnActionEvent) {
        e.presentation.isEnabled = true
    }
}
